<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>


<!DOCTYPE html>
<html>
<head>
     <title>上传模型</title>
    <meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
   
   <link href="${pageContext.request.contextPath}/Themes/default/Content/CSS/reset.css" rel="stylesheet" />
    <link href="${pageContext.request.contextPath}/Themes/default/Content/CSS/Style.css" rel="stylesheet" />
    <link href="${pageContext.request.contextPath}/Themes/default/Content/CSS/responsive.css" rel="stylesheet" />
    <link href="${pageContext.request.contextPath}/Content/bootstrap/css/bootstrap.css" rel="stylesheet">
    <link rel="icon" href="${pageContext.request.contextPath}/Themes/default/Content/webimg/bimlogo.ico" type="img/x-ico" />
  
    <link href="${pageContext.request.contextPath}/Content/plugins/plupload-2.1.2/js/jquery.plupload.queue/css/jquery.plupload.queue.css"
        rel="stylesheet" type="text/css" media="screen" />
    
    
    <style>
        /*.ztree li a {
            color: white;
        }*/
    </style>

        <script src="${pageContext.request.contextPath}/Themes/default/Content/Scripts/jquery.min.js"></script>
    <script src="${pageContext.request.contextPath}/Themes/default/Content/Scripts/Common.js"></script>
</head>
<body class="hold-transition skin-blue sidebar-mini fixed">
    <div class="wrapper">
        
        <div class="content-wrapper" id="content-wrapper">
            



            <div>
                
<div class="mymodel_right">
    <form id="UploadModelForm" action="${pageContext.request.contextPath}/UploadModel/UploadFile" method="post" enctype="multipart/form-data">

        <div class="title" style=" width: 100px; float: left;">模型名称：</div>
        <div class="box" style="width: 370px; float: left;">
            <input name="ModelName" id="ModelName" type="text" class="txtbox" /></div>
        <div class="modellist">
            <input type="hidden" id="hid_modelFile" name="hid_modelFile" value="" />
            <div id="divuploader">
                <div id="uploader" style="overflow: hidden; padding: 0; width: 480px;">
                </div>
            </div>
            <div id="divreupload">
                <!-- <div class="button float-none" id="BtnReupload">重新上传</div>-->
            </div>
            <span style="color: red; margin-left: 10px;">注：支持上传格式:rar,
                引擎支持文件格式有：ifc、obj、dae、3ds、fbx,转化时请注意将文件或文件夹压缩成*.rar(注意：（obj、dae、3ds、fbx）在压缩时需要用文件夹包含),ifc格式不需要文件夹包含。</span>
        </div>
        <div class="title"  style=" width: 220px; float: left;">建模所使用的工具软件及版本：</div>
        <div class="box" style=" width: 150px; float: left;">
            <select id="selTools" name="selTools" style="height:25px!important"  class="txtbox">
                <option value="">请选择</option>
                <option value="Revit">Revit</option>
                <option value="3DMAX">3DMAX</option>
                <option value="SketchUp">SketchUp</option>
                <option value="CATIA">CATIA</option>
                <option value="TeKla">TeKla</option>
            </select>

        </div>
         <div class="title" style="display:none">是否公开:<label><input type="radio" name="rboIsPublic" value="0" checked />是</label>
            &nbsp;&nbsp;<label><input type="radio" name="rboIsPublic" value="1" />否</label></div>
         <div class="box" style="padding-top: 40px;">
        <input name="MileageID" id="MileageID" type="hidden" />
        <input value="确定" onclick="uploadModelFile()" class="up_btn_grey" type="button" id="btn_submit" />
             </div>

    </form>
</div>

<hr />

            </div>
        </div>
    </div>

    <script src="${pageContext.request.contextPath}/Content/bootstrap/js/bootstrap.js"></script>
<script src="${pageContext.request.contextPath}/Content/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.js"></script>
<script src="${pageContext.request.contextPath}/Content/plugins/slimScroll/jquery.slimscroll.js"></script>
<script src="${pageContext.request.contextPath}/Content/plugins/fastclick/fastclick.js"></script>
<script src="${pageContext.request.contextPath}/Content/AdminLTE/js/app.js"></script>
<script src="${pageContext.request.contextPath}/Content/AdminLTE/js/demo.js"></script>
<script src="${pageContext.request.contextPath}/Content/plugins/pace/pace.js"></script>
<script src="${pageContext.request.contextPath}/Content/plugins/layer/layer.js"></script>
<script src="${pageContext.request.contextPath}/Content/plugins/datatables/jquery.dataTables.js"></script>
<script src="${pageContext.request.contextPath}/Content/plugins/datatables/dataTables.bootstrap.js"></script>

    
    <script src="${pageContext.request.contextPath}/Content/plugins/jquery-validation/jquery.unobtrusive-ajax.js"></script>
<script src="${pageContext.request.contextPath}/Content/plugins/jquery-validation/jquery.validate.js"></script>
<script src="${pageContext.request.contextPath}/Content/plugins/jquery-validation/jquery.validate.unobtrusive.js"></script>
<script src="${pageContext.request.contextPath}/Content/plugins/jQuery/jquery.form.js"></script>
<script src="${pageContext.request.contextPath}/Content/plugins/momentjs/moment.js"></script>
<script src="${pageContext.request.contextPath}/Content/plugins/daterangepicker/daterangepicker.js"></script>
<script src="${pageContext.request.contextPath}/Content/plugins/datepicker/bootstrap-datepicker.js"></script>
<script src="${pageContext.request.contextPath}/Content/plugins/datepicker/locales/bootstrap-datepicker.zh-CN.js"></script>

   
    <script src="${pageContext.request.contextPath}/Content/plugins/plupload-2.1.2/js/plupload.full.min.js" type="text/javascript"></script>
    <script src="${pageContext.request.contextPath}/Content/plugins/plupload-2.1.2/js/jquery.plupload.queue/jquery.plupload.queue.min.js" type="text/javascript"></script>
    <script src="${pageContext.request.contextPath}/Content/plugins/plupload-2.1.2/js/i18n/zh_CN.js" type="text/javascript"></script>

    <script type="text/javascript">
        $(document).ready(function () {
            uploadFile();
        });

        function uploadFile() {
            $("#btn_submit").attr('disabled', true);
            var url = '/Content/plupload-2.1.2/plupload.flash.swf';
            var serverUrl = '/Common/UploadModels.ashx';
            var maxfilesize = '1024' + 'MB';
            $("#uploader").pluploadQueue({
                url: serverUrl, //服务器端响应页面
                max_file_size: maxfilesize, //最大文件限制
                chunk_size: '2MB', //一次上传数据大小
                silverlight_xap_url: '/Content/plugins/plupload-2.1.2/js/Moxie.xap',
                unique_names: false, //是否自动生成唯一名称
                multi_selection: false, //是否可以一次选择多个文件
                filters: [
                      { title: "模型", extensions: 'rar' }
                ],

                // SWF文件位置
                flash_swf_url: url,
                init: {
                    FilesAdded: function (up, files) {
                        var filename = files[0].name;
                        //验证是否包含中文
                        if (validFormat(filename)) {
                            //判断模型是否存在
                            $.get("${pageContext.request.contextPath}/Ajax/GetModelIsExist", { PlanPath: filename }, function (data) {
                                if (data > 0) {
                                    $('a.plupload_start').addClass('plupload_disabled');
                                    layer.msg("模型文件名已经存在,请重新命名！", { icon: 0 });
                                    jQuery.each(up.files, function (i, file) {
                                        //clearuploadFile("uploader", up, file, 1);
                                        if (up.files.length <= 1) {
                                            return;
                                        }
                                        up.removeFile(file);
                                    });
                                    up.getFile(files[i].id);
                                } else {
                                    $('a.plupload_start').removeClass('plupload_disabled');
                                }
                            })
                        } else {
                            $('a.plupload_start').addClass('plupload_disabled');
                            layer.msg("模型文件名不能含有中文！", { icon: 0 });
                        }
                    },
                    FileUploaded: function (up, file, info) {
                        //一个文件上传成功
                        var newres = info.response;
                        jQuery("#hid_modelFile").val(newres);
                        $("#btn_submit").attr('disabled', false);
                        $("#btn_submit").removeClass("up_btn_grey").addClass("up_btn");
                        $(".boxloading").hide();
                    },
                    BeforeUpload: function (up, file) {
                        $(".boxloading").show();
                    },
                    Init: function (up) {
                        jQuery("#uploader_filelist").height(45);
                    },
                    Error: function (up, args) {
                        //发生错误
                        if (args.code == up.FILE_SIZE_ERROR) {
                            //alert("单个文件不得大于 " + maxfilesize + "（" + args.file.name + "）");
                            layer.msg(("单个文件不得大于 " + maxfilesize + "（" + args.file.name + "）", { icon: 0 }));
                        }
                    }
                }
            });


        }
        function uploadModelFile() {
            $("#MileageID").val(GetUrlParam("MileageID"));
            if ($.trim($("#ModelName").val()) == "") {
                layer.msg("请填写模型名称！", { icon: 0 });
            } else if ($.trim($("#selTools").val()) == "") {
                layer.msg("请选择建模工具！", { icon: 0 });
            } else {
                if ($("#hid_modelFile").val()) {
                    layer.load();
                    $("#UploadModelForm").ajaxSubmit(function (d) {
                        layer.closeAll();
                        if (d == "成功") {
                            layer.msg('添加成功！', {
                                icon: 1, time: 2000, end: function () {
                                    parent.window.location.href = "${pageContext.request.contextPath}/Home/ModelList";
                                    var index = parent.layer.getFrameIndex(window.name);
                                    console.log(index);
                                    parent.layer.close(index);
                                }
                            });
                        } else {
                            layer.msg('上传失败！', { icon: 2 });
                        }
                    });
                }
                else {
                    alert("请选择文件！");
                }
            }

        }
        var setting = {
            view: { selectedMulti: false },
            callback: { onClick: onClick },
            data: {
                simpleData: {
                    enable: true,
                    idKey: "MileageID",
                    pIdKey: "ParentMileageID",
                    rootPId: ""
                },
                key: {
                    name: "MileageName",
                    title: ""
                }
            }
        };
        function onClick(event, treeId, treeNode, clickFlag) {
            $("#treeSelectedNodeName").val(treeNode.MileageName);
            $("#treeSelectedNodeId").val(treeNode.MileageID);
            $("#MileageID").val(treeNode.MileageID);
            $("#treeSelectedNodePId").val(treeNode.ParentMileageID);
            var parentNode = treeNode.getParentNode();
            if (parentNode) {
                $("#treeParentNodeName").text(parentNode.MileageName);
            }
            else {
                $("#treeParentNodeName").text("根节点");
            }
            $("#TreeForm input[type='button']").show();
            $("#TreeForm input[type='submit']").hide();
            $("#TreeForm #submitbutton").hide();
            $("#treeSelectedNodeName").attr("readonly", "readonly");
        }
        var zNodes = [
            { id: 4, pId: 0, name: "父节点2" },
			{ id: 34, pId: 4, name: "叶子节点4" },
            { id: 89, pId: 34, name: "叶子节点9" },
			{ id: 35, pId: 4, name: "叶子节点5" },
			{ id: 36, pId: 4, name: "叶子节点6" }
        ];
        function appendChildNode() {
            $("#treeParentNodeName").text($("#treeSelectedNodeName").val());
            $("#treeSelectedNodePId").val($("#treeSelectedNodeId").val());
            $("#treeSelectedNodeName").val("");
            $("#treeSelectedNodeId").val("");
            $("#TreeForm input[type='button']").hide();
            $("#TreeForm #submitbutton").show();
            $("#treeSelectedNodeName").attr("readonly", false);
            if (!$("#treeSelectedNodePId").val()) {
                $("#treeParentNodeName").text("根节点");
            }
        }
        function editThisNode() {
            if (!$("#treeSelectedNodeId").val()) {
                layer.msg("请选择一个节点！", { icon: 0 });
                return;
            }
            $("#TreeForm input[type='button']").hide();
            $("#TreeForm #submitbutton").show();
            $("#treeSelectedNodeName").attr("readonly", false);
        }
        function submitFun() {
            if ($("#treeSelectedNodeName").val()) {
                $("#TreeForm").ajaxSubmit(function (d) {
                    if (d == 1) {
                        layer.msg("提交成功！", { icon: 1 });
                        window.location.reload();
                    }
                });
            }
            else {
                layer.msg("节点名必填！", { icon: 0 });
                return false;
            }
        }
        $(function () {
            $.get("${pageContext.request.contextPath}/Ajax/GetModelTreeData", function (d) {
                zNodes = d;
                $.fn.zTree.init($("#tree"), setting, zNodes);
            })
        })

        //获取URL参数
        function GetUrlParam(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var r = window.parent.location.search.substr(1).match(reg);
            if (r != null) return decodeURI(r[2]); return null;
        }
        //验证中文
        function validFormat(val) {
            if (escape(val).indexOf("%u") < 0) {
                return true;
            }
            else {
                return false;
            }
        }
    </script>


   
</body>
</html>

